package com.rc.saas.tenant.service.ugs;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.base.BaseSearch;
import com.rc.saas.tenant.config.UpYunConfig;
import com.rc.saas.tenant.mapper.ugs.TenantUgsSuperLevelPriceMapper;
import com.rc.saas.tenant.model.ugs.TenantUgsSuperLevelPrice;
import com.rc.saas.tenant.model.ugs.TenantUgsSuperLevelPriceExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author frog
 * @date 2021/4/8
 */
@Service
public class TenantUgsSuperLevelPriceServiceImpl implements TenantUgsSuperLevelPriceService {

    @Autowired
    private TenantUgsSuperLevelPriceMapper tenantUgsSuperLevelPriceMapper;

    @Autowired
    private UpYunConfig upYunConfig;

    @Override
    public TenantUgsSuperLevelPriceMapper getMapper() {
        return tenantUgsSuperLevelPriceMapper;
    }

    @Override
    public PageInfo<TenantUgsSuperLevelPrice> listPageTenantUgsSuperLevelPrice(BaseSearch search) {
        PageHelper.startPage(search.getOffset(), search.getLimit());
        TenantUgsSuperLevelPriceExample example = new TenantUgsSuperLevelPriceExample();
        example.createCriteria().andTenantCodeEqualTo(search.getTenantCode());
        List<TenantUgsSuperLevelPrice> tenantUgsSuperLevelPrices = tenantUgsSuperLevelPriceMapper.selectByExample(example);
        for (TenantUgsSuperLevelPrice tenantUgsSuperLevelPrice : tenantUgsSuperLevelPrices) {
            tenantUgsSuperLevelPrice.setSuperCardImg(upYunConfig.getDownloadRoot() + tenantUgsSuperLevelPrice.getSuperCardImg());
        }
        return new PageInfo<TenantUgsSuperLevelPrice>(tenantUgsSuperLevelPrices);
    }
}
